package com.kofigyan.stateprogressbarsample;

import com.kofigyan.stateprogressbarsample.not_stateprogressbar.pojo.MenuItem;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.ListContainer;
import ohos.utils.IntentConstants;
import ohos.utils.net.Uri;

public abstract class ListBaseActivity extends BaseAbility {

    protected ListContainer recyclerView;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        injectCommonViews();
    }

    protected void injectCommonViews() {
        recyclerView = (ListContainer) findComponentById(ResourceTable.Id_rv);
    }

    @Override
    protected void initMenuData() {
        types.add(new MenuItem(0, "viewGithub"));
        types.add(new MenuItem(1, "feedback"));
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getId()) {
            case 0:
                Uri contentUrl = Uri.parse("https://github.com/kofigyan/StateProgressBar");
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withUri(contentUrl)
                        .withAction("android.intent.action.VIEW")
                        .withFlags(Intent.FLAG_NOT_OHOS_COMPONENT)
                        .build();
                intent.setUriAndType(contentUrl, null);
                intent.setOperation(operation);
                startAbility(intent, 0);
                break;
            case 1:
                Intent intentEmail = new Intent();
                Operation operationEmial = new Intent.OperationBuilder()
                        .withAction(IntentConstants.ACTION_SEND_SMS)
                        .withUri(Uri.parse("mailto:" + "kofigyan2011@gmail.com"))
                        .build();
                intentEmail.setOperation(operationEmial);
                startAbility(intentEmail);
                break;
        }
        return true;
    }
}
